{% set pypi_name = 'murano-dashboard' %}
{% set upstream_version = upstream_version('10.0.0') %}
{% set rpm_release = '1' %}

%global sname {{ pypi_name }}
%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%global http_dashboard_dir %{_datarootdir}/openstack-dashboard
%else
%global http_dashboard_dir /srv/www/openstack-dashboard
%endif
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        The Murano Dashboard
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://wiki.openstack.org/wiki/Murano
Source0:        https://files.pythonhosted.org/packages/source/m/%{sname}/%{sname}-{{upstream_version}}.tar.gz
BuildRequires:  fdupes
BuildRequires:  {{ py3('horizon') }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('python-muranoclient') }}
BuildRequires:  {{ py3('pbr') }}
Requires:       {{ py3('horizon-plugin-murano-ui') }} = %{version}
BuildArch:      noarch

%description
The Murano UI Horizon plugin adds Murano panel to the OpenStack dashboard.

%package -n    {{ py3('horizon-plugin-murano-ui') }}
Summary:       The Murano Dashboard - Python module
Requires:      {{ py3('Babel') }}
Requires:      {{ py3('Django') }}
Requires:      {{ py3('PyYAML') }}
Requires:      {{ py3('beautifulsoup4') }}
Requires:      {{ py3('django-babel') }}
Requires:      {{ py3('django-formtools') }}
Requires:      {{ py3('python-muranoclient') }}
Requires:      {{ py3('oslo.log') }}
Requires:      {{ py3('pbr') }}
Requires:      {{ py3('semantic_version') }}
Requires:      {{ py3('yaql') }}

%description -n {{ py3('horizon-plugin-murano-ui') }}
The Murano UI Horizon plugin adds Murano panel to the OpenStack dashboard.

%prep
%autosetup -n %{sname}-{{upstream_version}}
%py_req_cleanup

%build
%py3_build

%install
%py3_install

install -m 0755 -d %{buildroot}%{http_dashboard_dir}/openstack_dashboard/enabled/
cp -a muranodashboard/local/enabled/*.py* %{buildroot}%{http_dashboard_dir}/openstack_dashboard/enabled/
install -m 0755 -d %{buildroot}%{http_dashboard_dir}/openstack_dashboard/local/local_settings.d/
cp -a muranodashboard/local/local_settings.d/_50_murano.py %{buildroot}%{http_dashboard_dir}/openstack_dashboard/local/local_settings.d/_50_murano.py.example
install -m 0755 -d %{buildroot}%{http_dashboard_dir}/openstack_dashboard/conf/
cp -a muranodashboard/conf/murano_policy.json %{buildroot}%{http_dashboard_dir}/openstack_dashboard/conf/

%fdupes %{buildroot}%{http_dashboard_dir}

%post
su %{apache_user} -s /bin/sh -c "python3 %{http_dashboard_dir}/manage.py collectstatic --noinput --clear > /dev/null"

%postun
su %{apache_user} -s /bin/sh -c "python3 %{http_dashboard_dir}/manage.py collectstatic --noinput --clear > /dev/null"

%files
%doc ChangeLog README.rst
%license LICENSE
%{http_dashboard_dir}/openstack_dashboard/enabled/_5*.py*
%{http_dashboard_dir}/openstack_dashboard/enabled/_6*.py*
%{http_dashboard_dir}/openstack_dashboard/enabled/_7*.py*
%{http_dashboard_dir}/openstack_dashboard/enabled/_8*.py*
%{http_dashboard_dir}/openstack_dashboard/local/local_settings.d/_50_murano.py.example
%{http_dashboard_dir}/openstack_dashboard/conf/murano_policy.json

%files -n {{ py3('horizon-plugin-murano-ui') }}
%doc README.rst
%license LICENSE
%{python3_sitelib}/muranodashboard
%{python3_sitelib}/murano_dashboard-*.egg-info

%changelog
